package com.lc.boxuegu.M_isValidBST;

/**
 * @author zhaiyj
 * @date 2025/6/17 20:58
 */
public class Solution {


    public boolean isValidBST(TreeNode root) {
        return isValidBST(root, Long.MIN_VALUE, Long.MAX_VALUE);
    }

    private boolean isValidBST(TreeNode node, long left, long right) {
        if(node == null){
            return true;
        }

        long x = node.val;
        return left < x && x < right  && isValidBST(node.left, left, x) && isValidBST(node.right, x, right);
    }


    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }


}
